package main.java;

import java.io.InputStream;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

public class AuthorityDownAction implements Action {
	private String inputPath;

	public void setInputPath(String value) {
		inputPath = value;
	}

	// ServletContext提供getResourceAsStream()方法
	// 返回指定文件对应的输入流
	public InputStream getTargetFile() throws Exception {
		return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
	}

	public String execute() throws Exception {
		// 取得ActionContext实例
		ActionContext ctx = ActionContext.getContext();
		// 通过ActionContext访问用户的HttpSession
		Map<String, Object> session = ctx.getSession();
		String user = (String) session.get("user");
		// 判断Session里的user是否通过检查
		if (user != null && user.equals("chen")) {
			return SUCCESS;
		}
		ctx.put("tip", "用户名错误，请重新登录！");
		return LOGIN;
	}
}
